﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Omniscient.Foundation.Data;
using Omniscient.TimeTracker.Data;
using Omniscient.Foundation.ApplicationModel;

namespace Omniscient.TimeTracker.Server
{
    public class TimeEntryAdapterService: IEntityAdapter<TimeEntry>
    {
        private IEntityAdapter<TimeEntry> _adapter;

        public TimeEntryAdapterService()
        {
            _adapter = ApplicationManager.Current.ObjectContainer.Get<IEntityAdapter<TimeEntry>>();    
        }

        #region IEntityAdapter<TimeEntry> Members

        public EntityList<TimeEntry> LoadAll()
        {
            if (_adapter == null) return null;
            return _adapter.LoadAll();
        }

        public EntityList<TimeEntry> LoadByForeignKey(string propertyName, Guid id)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByForeignKey(propertyName, id);
        }

        public TimeEntry LoadByKey(Guid id)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByKey(id);
        }

        public EntityList<TimeEntry> LoadByObjectQuery(Omniscient.Foundation.Data.ObjectQuery.OQuery<TimeEntry> query)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByObjectQuery(query);
        }

        public EntityList<TimeEntry> LoadByQuery(string queryName)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByQuery(queryName);
        }

        public EntityList<TimeEntry> LoadByValueProperty(string propertyName, object value)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByValueProperty(propertyName, value);
        }

        public void Save(IEnumerable<TimeEntry> entities)
        {
            if (_adapter == null) return;
            _adapter.Save(entities);
        }

        public void Save(TimeEntry entity)
        {
            if (_adapter == null) return;
            _adapter.Save(entity);
        }

        #endregion
    }
}
